// components/base/filter-bar/index.js
const componentBehavior = require('../../../behaviors/component');
const { COMPONENT_OPTIONS } = require('../../../constants/common');

Component({
    behaviors: [componentBehavior],
    options: {
        ...COMPONENT_OPTIONS,
    },
    properties: {
        multiple: {
            type: Boolean,
            value: false,
        },
        options: {
            type: Array,
            value: [],
        },
        value: {
            type: Object,
            value: {},
        },
    },
    data: {
    },
    methods: {
        handleChange(e) {
            const { key } = e.currentTarget.dataset;
            let { multiple, value } = this.data;
            if (!multiple) {
                for (const i in value) {
                    if (i !== key) {
                        delete value[i];
                    }
                }
            }
            if (!value[key]) {
                value[key] = 'desc';
            } else if (value[key] === 'asc') {
                value[key] = 'desc';
            } else if (value[key] === 'desc') {
                value[key] = 'asc';
            }
            this.triggerEvent('change', value);
        },
    }
})
